unit UretimAdetliTakip;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, wwdblook, StdCtrls,
  wwdbdatetimepicker, ExtCtrls, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, ADODB, Mask, wwdbedit, Wwdotdot, Wwdbcomb,
  Buttons, Data, unitortak, cxDBLookupComboBox, cxCustomPivotGrid,
  cxDBPivotGrid, ComCtrls, cxCurrencyEdit, Wwdbspin;

type
  TUretimAdetliTakipF = class(TForm)
    Panel2: TPanel;
    Label7: TLabel;
    Label8: TLabel;
    Label3: TLabel;
    t2: TwwDBDateTimePicker;
    t1: TwwDBDateTimePicker;
    Label1: TLabel;
    TarihTipiK: TwwDBComboBox;
    UretimAdetliTakipQ: TADOQuery;
    UretimAdetliTakipQS: TDataSource;
    Panel1: TPanel;
    bYenile: TButton;
    bkapat: TBitBtn;
    adoTur: TADOQuery;
    lcTur: TwwDBLookupCombo;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    PivotGrid1: TcxDBPivotGrid;
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1DBTableView1UretimNo: TcxGridDBColumn;
    cxGrid1DBTableView1UremriTarih: TcxGridDBColumn;
    cxGrid1DBTableView1stokkodu: TcxGridDBColumn;
    cxGrid1DBTableView1Cinsi: TcxGridDBColumn;
    cxGrid1DBTableView1miktar: TcxGridDBColumn;
    cxGrid1DBTableView1UstGrupId: TcxGridDBColumn;
    cxGrid1DBTableView1GrupId: TcxGridDBColumn;
    cxGrid1DBTableView1ModelId: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    PivotGrid1UretimNo: TcxDBPivotGridField;
    PivotGrid1UremriTarih: TcxDBPivotGridField;
    PivotGrid1Stokkodu: TcxDBPivotGridField;
    PivotGrid1Cinsi: TcxDBPivotGridField;
    PivotGrid1UstGrupId: TcxDBPivotGridField;
    PivotGrid1GrupId: TcxDBPivotGridField;
    PivotGrid1ModelId: TcxDBPivotGridField;
    PivotGrid1Miktar: TcxDBPivotGridField;
    cxGrid1DBTableView1UretimSn: TcxGridDBColumn;
    cxGrid1DBTableView1ToplamUretimDk: TcxGridDBColumn;
    PivotGrid1UretimSn: TcxDBPivotGridField;
    PivotGrid1ToplamUretimDk: TcxDBPivotGridField;
    edBoluncek: TwwDBSpinEdit;
    Label2: TLabel;
    procedure bkapatClick(Sender: TObject);
    procedure bYenileClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  UretimAdetliTakipF: TUretimAdetliTakipF;

implementation

{$R *.dfm}

procedure TUretimAdetliTakipF.bkapatClick(Sender: TObject);
begin
  close;
end;

procedure TUretimAdetliTakipF.bYenileClick(Sender: TObject);
begin
  UretimAdetliTakipQ.close;
  UretimAdetliTakipQ.SQL.Text := 'select uretim.UretimNo,UremriTarih=UrEmri.Tarih,Stok.Stokkodu,Stok.Cinsi,Stok.UstGrupId,Stok.GrupId,Stok.ModelId,Miktar=Count(*),' +
    ' UretimSn=us.Sure,ToplamUretimDk=(Count(*)*us.Sure)/(60.00*' + FloatToStr(edBoluncek.Value) + ') from uretim ';
  UretimAdetliTakipQ.SQL.Add(' join Stok on (Uretim.UretimKod=Stok.Stokkod)');
  UretimAdetliTakipQ.SQL.Add(' join UrEmri on (UrEmri.Emirno=uretim.UretimNo)');
  UretimAdetliTakipQ.SQL.Add(' left join TblUretimSureTanim us on (us.ModelId=Stok.ModelId)');
  UretimAdetliTakipQ.SQL.Add('where uretim.' + TarihTipiK.Value + '>=' + #39 +
    TarihDonustur(t1.date, srvCasper, '') + #39 + ' and uretim.' + TarihTipiK.Value + '<' + #39 +
    TarihDonustur(t2.date + 1, srvCasper, '') + #39);

  if (LcTur.Text <> '') then
  begin
    if adoTur.Locate('Ref', LcTur.LookupValue, []) then
    begin
      if AdoTur.FieldByName('UstGrupId').AsString <> '' then
        UretimAdetliTakipQ.sql.Add(' AND Stok.UstGrupId=' + AdoTur.FieldByName('UstGrupId').AsString);

      if AdoTur.FieldByName('GrupId').AsString <> '' then
        UretimAdetliTakipQ.sql.Add(' AND Stok.GrupId=' + AdoTur.FieldByName('GrupId').AsString);

      if AdoTur.FieldByName('ModelId').AsString <> '' then
        UretimAdetliTakipQ.sql.Add(' AND Stok.ModelId=' + AdoTur.FieldByName('ModelId').AsString);
    end;
  end;

  UretimAdetliTakipQ.SQL.Add(' group by us.Sure,uretim.UretimNo,UrEmri.Tarih,Stok.Stokkodu,Stok.Cinsi,Stok.UstGrupId,Stok.GrupId,Stok.ModelId order by uretim.UretimNo');

{
  UretimAdetliTakipQ.SQL.Text :=
    'select emirno,max(uremri.tarih) as Emirtarihi,max(uremri.stokkodu) as stokkodu,count(*) as miktar from uretim,uremri';
  UretimAdetliTakipQ.SQL.Add('where uretim.' + TarihTipiK.Value + '>=' + #39 +
    TarihDonustur(t1.date, srvCasper, '') + #39 + ' and uretim.' + TarihTipiK.Value + '<' + #39 +
    TarihDonustur(t2.date + 1, srvCasper, '') + #39 +
    ' and uremri.emirno=uretim.uretimno ');

  if (LcTur.Text <> '') then
  begin
    if adoTur.Locate('Ref', LcTur.LookupValue, []) then
    begin
      if AdoTur.FieldByName('UstGrupId').AsString <> '' then
        UretimAdetliTakipQ.sql.Add(' AND (select UstGrupId from stok where stok.stokkod=uretim.uretimkod)=' + AdoTur.FieldByName('UstGrupId').AsString);

      if AdoTur.FieldByName('GrupId').AsString <> '' then
        UretimAdetliTakipQ.sql.Add(' AND (select GrupId from stok where stok.stokkod=uretim.uretimkod)=' + AdoTur.FieldByName('GrupId').AsString);

      if AdoTur.FieldByName('ModelId').AsString <> '' then
        UretimAdetliTakipQ.sql.Add(' AND (select ModelId from stok where stok.stokkod=uretim.uretimkod)=' + AdoTur.FieldByName('ModelId').AsString);
    end;
  end;

  UretimAdetliTakipQ.SQL.Add(' group by emirno order by emirno');
  }
  UretimAdetliTakipQ.open;
end;

procedure TUretimAdetliTakipF.FormShow(Sender: TObject);
begin
  AdoTur.Open;

  YerAyarla(Self, false);

  TarihTipiK.ItemIndex := 0;
  t1.Date := SadeceTarih;
  t2.Date := SadeceTarih;
  byenile.click;

end;

procedure TUretimAdetliTakipF.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := CaFree;
  UretimAdetliTakipF := nil;
end;

end.

